mod controller;
mod dto;
mod entity;
mod mapper;
mod middleware;
mod service;
mod utils;
mod websocket;

use crate::controller::router;
use hypers::once_cell::sync::Lazy;
use hypers::prelude::{Result, Router};
use rbatis::RBatis;
use redis::Client;

pub static GLOBAL_DB: Lazy<RBatis> = Lazy::new(|| RBatis::new());

pub static GLOBAL_REDIS: Lazy<Client> =
    Lazy::new(|| Client::open("redis://127.0.0.1/").expect("连接redis失败"));

#[tokio::main]
async fn main() -> Result<()> {
    log4rs::init_file("log4rs.yaml", Default::default()).unwrap();
    // 连接数据库
    utils::mysql::init_db().await;
    log::info!("数据库连接成功");

    let mut root = Router::default();
    router(&mut root);

    // println!("root = {:#?}", root);
    let addr = "0.0.0.0:8090";
    log::info!("Vist browser http://{}/swagger_ui/", addr);
    let listener = hypers::TcpListener::bind(addr).await?;
    hypers::listen(root, listener).await
}
